class AccountsController < ApplicationController
  
    before_filter :ensure_login
    #before_filter :ensure_logout, :only => [:new, :create]
   
    def index
        @accounts = Account.find(:all)
    end
   
    def show
        @account = Account.find(params[:id])
    end
   
    def new
        @account = Account.new
    end
   
    def create
        @account = Account.new(params[:account])
        if @account.save
          flash[:notice] = "Le compte #{@account.login} a bien été créé!"
          redirect_to @account
          #@session = @account.sessions.create
          #session[:id] = @session.id
          
        else
          render(:action => 'new')
        end
    end
    
    
    def edit
        #@account = Account.find(@user)
        @account = Account.find(params[:id])
    end
   
    def update
        @account = Account.find(params[:id])
        #@account = Account.find(@user)
        if @account.update_attributes(params[:account])
          flash[:notice] = "Le compte a été modifié !"
          redirect_to @account
          #redirect_to(root_url)
        else
          render(:action => 'edit')
        end
    end
   
    def destroy
        @account = Account.find(params[:id])
        @account.destroy
        redirect_to(accounts_url)
        #session[:id] = @user = nil
        #flash[:notice] = "You are now unregistered"
        
    end
  
end
